package com.cloud.test03;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 响应数据：两个Stream,在一个servlet中不能同时调用两种流
 * response对象只能相应一次，则当调用第二种流时会出错 java.lang.IllegalStateException: 已为此响应调用getWriter（）
 * getWriter()  PrintWriter getWriter() throws IOException;
 *      a text output stream.Only for ""
 * getOutPutStream  ServletOutputStream getOutputStream() throws IOException;
 *      output stream for any data
 * @author DELL
 */
@WebServlet(value = {"/ResTest01", "/restest01"})
public class ResponseTest01 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.getWriter().write("Hello!");
        response.getWriter().close();
        //response.getOutputStream().println("Hello again!");
    }
}
